#include "stdio.h"
#include "math.h"
#include "string.h"
#define N 251
int shu[N][N];
int tt[N][N][2];

main()
{

    int i,j,l,n,b,x,y,tox,toy;
    int max,min;
    long k;
    
//    freopen("2019.in","r",stdin);
    
    memset(tt,0,sizeof(tt));
    memset(shu,0,sizeof(shu));
    scanf("%d%d%ld",&n,&b,&k);
    for (i=1;i<=n;i++)
    	for (j=1;j<=n;j++)
    		scanf("%d",&shu[i][j]);
    		
	while (k-->0)
	{
	    scanf("%d%d",&x,&y);
	    if (tt[x][y][0]==0)
	    {
        	    tox=x+b-1;
             	toy=y+b-1;
        	    max=min=shu[x][y];
        	    for (i=x;i<=tox;i++)
        	    	for (j=y;j<=toy;j++)
        	    	{
        	    	    if (max<shu[i][j]) max=shu[i][j];
        	    	    if (min>shu[i][j]) min=shu[i][j];
        	    	    tt[x][y][1]=max-min;
        	    	} 
                tt[x][y][0]=1;   
		}
	    printf("%d\n",tt[x][y][1]);
	    
	}    
	
	return 0;
}    